home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / StyleTagsAutoCreate.pprx < prev    next >
Text File  |  1993-05-25  |  23KB  |  567 lines

  1. /* This genie creates new style tags automatically by examining all the text in a document. If any text is in a style which does not match an existing tag, a new tag is created and the text is set to that tag. Tags are named with a simplified description of the typeface; you can alter any of these names to anything you wish (using the "Style Tags Modify" menu item). If you modify the tag, its typeface name might no longer suit it. 
  2. Don Cox © Sept 92  Not Public Domain. All rights reserved. */
  3.  
  4. /* Method: load in typographic data from article texts. If an existing style is used, see if it is modified (further data after the style name). Ignore any data for text after the first letter. If no existing style is used, assemble the data and compare with all existing styles to see if there is a match. If not, suggest a name for a new style, create it and apply it to the block. */
  5.  
  6.  
  7. trace n
  8. if ~show(l, "gdarexxsupport.library") then
  9.     if ~(exists("libs:gdarexxsupport.library") & addlib("gdarexxsupport.library", 0, -30)) then
  10.         exit_msg("Please install the gdarexxsupport.library in your libs: directory before running this Genie")
  11.     
  12.  
  13. address command
  14. call SafeEndEdit.rexx()
  15. call ppm_AutoUpdate(0)
  16.  
  17. prevdoc  = ppm_GetDocName()
  18.  
  19. if ppm_DocChanged() then
  20. do
  21.     if ppm_SavedDate() = "Not Saved" then prevdoc = ""
  22.  
  23.     if ppm_Inform(2, "You must save the document first. Save and continue?", "Cancel", "Ok") then
  24.                 call ppm_SaveDocument(prevdoc)
  25.     else
  26.             exit_msg(0,)
  27.  
  28.     prevdoc = ppm_GetDocName()
  29. end
  30.  
  31. colormode = ppm_GetColorMode()
  32. call ppm_SetColorMode(0)
  33. cpage   = ppm_CurrentPage()
  34.  
  35.  
  36. tolerant = ppm_Inform(2,"Ignore bold, italic and underline?","No","Yes")
  37. call ppm_ShowStatus("Working..")
  38.  
  39. existing = 0   /* flag for style matching existing style  */
  40. randval = (randu() * time(s)) % 1 /* mark boxes with random number to avoid doing them twice */
  41. box = ppm_DocFirstBox()
  42.  
  43. do while box ~= 0
  44.  
  45.     info    = upper(word(ppm_GetBoxInfo(box), 1))
  46.  
  47.     if (info = "TEXT") & (ppm_GetBoxUserData(box) ~= randval) then do
  48.         oldbox = box
  49.         box = ppm_ArtFirstBox(box)
  50.         text = ppm_GetArticleText(box, 1)
  51.         call ppm_ShowStatus("  Analysing article that begins in box "box)
  52.         if text  = '' then iterate
  53.  
  54.         paraname = ""
  55.         paracode = ""
  56.         stylename = ""
  57.         stylecode = ""
  58.         fontname = ""
  59.         typestyle = ""
  60.         fontsize = ""
  61.         bold = ""
  62.         italic = ""
  63.         underline = ""
  64.         outline = ""
  65.         kerning = ""
  66.         hyphenation = ""
  67.         linespace = ""
  68.         linespacecode = ""
  69.         lineshift = ""
  70.         tracking = ""
  71.         colour = ""
  72.         justification = ""
  73.  
  74. position = 1
  75. trace n
  76.         do x = 1 to 10000  /* big number - go right through article  */
  77.             change = 0
  78.             notcode = 0
  79.             position = parsecodes(position) /* parse a block of codes in text */
  80.             if position = 0 then break
  81.             if stylecode = "dS" then iterate
  82.             if notcode = 1 then iterate   /* non-style codes  */
  83.  
  84. /* put together style definition from text */
  85.             trackstring = "\t<"tracking">"
  86.             if tracking = "" then trackstring = ""
  87.             linespacestring = "\"linespacecode"<"||linespace||">"
  88.             if linespacecode = "" | linespacecode = "" then linespacestring = ""
  89.             fontnamestring = "\ff<"fontname">"
  90.             if fontname = "" then fontnamestring = ""
  91.             fontsizestring = "\fs<"fontsize">"
  92.             if fontsize = "" then fontsizestring = ""
  93.             colourstring = "\c<"colour">"
  94.             if colour = "" then colourstring = ""
  95.             styledefinition = "\"paracode||paraname ||typestyle ||bold ||italic ||outline ||underline || fontnamestring|| fontsizestring|| justification|| kerning|| hyphenation|| linespacestring|| trackstring||colourstring
  96.             
  97.             if tolerant = 1 then styledefinition = "\"paracode||paraname || fontnamestring|| fontsizestring|| justification|| kerning|| hyphenation|| linespacestring|| trackstring||colourstring
  98.             
  99. /* see if new definition matches any of the old ones */
  100.             stylelist = ppm_GetStyleTagList()
  101.             stylelistTest = stylelist||"0a"x
  102.             parse var stylelist NumberOfTags "0a"x stylelist
  103.  
  104.             if NumberOfTags~=0 then do
  105.                 do t=1 to NumberOfTags
  106.                     parse var stylelist thisname "0a"x stylelist
  107.                     thisdata = ppm_GetStyleTagData(thisname)
  108.                     thisdata = substr(thisdata, pos("{",thisdata)+1)
  109.                     thisdata = left(thisdata, lastpos("}",thisdata)-1)
  110.                     if tolerant = 1 then do  /* take out unwanted codes */
  111.                         p=pos(thisdata,"\B")
  112.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  113.                         p=pos(thisdata,"\b")
  114.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  115.                         p=pos(thisdata,"\U")
  116.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  117.                         p=pos(thisdata,"\u")
  118.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  119.                         p=pos(thisdata,"\I")
  120.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  121.                         p=pos(thisdata,"\i")
  122.                         if p~=0 then thisdata = delstr(thisdata,p,2)
  123.                         end
  124.                     if thisdata = styledefinition then do
  125.                         ThisTagName = "\dS<"||thisname||">"
  126.                         if stylecode~= "dS" then text = insert(ThisTagName,text, position-2)
  127.                         change = 0 
  128.                         leave t
  129.                         end
  130.                     end   /* t=1 to NumberOfTags  */
  131.             end
  132.      
  133.             if change = 0 then iterate x   /* No need to make a new tag */
  134.  
  135.             
  136.             numbering = 1
  137.             newbold = ""
  138.             if right(bold,1) = "B" then newbold = "B"
  139.             newitalic = ""
  140.             if right(italic,1) = "I" then newitalic = "I"
  141.             suggestname = left(fontname, 9)||newbold||newitalic||"."||(fontsize%1)||"pt."||colour
  142.             testsuggest = "0a"x||suggestname||"0a"x
  143.     
  144.             do i = 1 to 999  /* if name already used, give it a new number */
  145.                 if pos(testsuggest,stylelistTest)=0 then break
  146.                 numbering = numbering+1
  147.                 suggestname = left(fontname, 9)||newbold||newitalic||"."||(fontsize%1)||"pt."||colour"."||right(numbering, 3,"0")
  148.                 testsuggest = "0a"x||suggestname||"0a"x
  149.                 end
  150.        
  151.             ThisTagName = "\dS<"||suggestname||">"
  152.             text = insert(ThisTagName,text, position-2)
  153.             position = position+3
  154.             styledefinition = "<"suggestname"{"styledefinition"}>"
  155.             call ppm_DefineStyleTag(styledefinition)      
  156.             end   /* of article text - position = 0  */
  157.       
  158. /* replace text with new version containing new style codes */
  159.         gone = ppm_DeleteContents(box)
  160.         overflow = ppm_TextIntoBox(box, text)
  161.         do while box ~= 0  /* mark all the other boxes in this chain  */
  162.             call ppm_SetBoxUserData(box, randval)
  163.             box = ppm_ArtNextBox(box)
  164.             end
  165.         box = oldbox  /* back to the box we are working on */
  166.         end
  167.  
  168.     box = ppm_DocNextBox(box)
  169.  
  170. end
  171.  
  172.  
  173. title = ppm_GetDocName()
  174. colon = lastpos('/', title)
  175. if colon = 0 then colon = pos(':', title)
  176. title = substr(title,colon+1)
  177.  
  178. datafile = "ram:"||title||".tags"
  179. stylelist = ppm_GetStyleTagList()
  180. parse var stylelist NumberOfTags "0a"x stylelist
  181. text ="List of style tags"||"0a0a"x
  182.  
  183. if NumberOfTags~=0 then do
  184.     do t=1 to NumberOfTags
  185.         parse var stylelist thisname "0a"x stylelist
  186.         thisdata = ppm_GetStyleTagData(thisname)
  187.         text = text||thisdata"0a"x
  188.         end   /* t=1 to NumberOfTags  */
  189.     end
  190.  
  191. paralist = ppm_GetParaTagList()
  192. parse var paralist NumberOfTags "0a"x paralist
  193. text =text||"0a"x||"List of paragraph tags"||"0a0a"x
  194.  
  195. if NumberOfTags~=0 then do
  196.     do t=1 to NumberOfTags
  197.         parse var paralist thisname "0a"x paralist
  198.         thisdata = ppm